package djrain.lilochat.client;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class LiloConfig extends Activity implements OnClickListener
{
	private static final String tag = "LiloConfig";
	private static final int GALLERY_IMAGE = 1000;
	private ImageView iam;
	private ImageView you;

	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lilo_config);
		iam = (ImageView)findViewById(R.id.iam_image);
		findViewById(R.id.iam).setOnClickListener(this);
		you = (ImageView)findViewById(R.id.you_image);
		findViewById(R.id.you).setOnClickListener(this);
	}
	

	public void onClick(View v)
	{
		getPictureFromGallery(v.getId());
	}
	

	public void getPictureFromGallery(int id)
	{
		Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
		//Intent intent = new Intent(Intent.ACTION_PICK);//or
		intent.setType("image/*");
		intent.putExtra("crop", "true");
		intent.putExtra("aspectX", 1); // 확대축소 비율
		intent.putExtra("aspectY", 1);

		intent.putExtra("outputX", 50);
		intent.putExtra("outputY", 50);
		intent.putExtra("return-data", true);
		startActivityForResult(intent, id);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if (resultCode != Activity.RESULT_OK)
			return;
		Bitmap bitmap = (Bitmap) data.getParcelableExtra("data");

		switch(requestCode){
		case R.id.iam:
			iam.setImageBitmap(bitmap);
			break;
		case R.id.you:
			you.setImageBitmap(bitmap);
			break;
		}
	}
}
